package factory;


import model.Edital;
import model.Lance;
import model.Perfil;
import model.Produto;
import model.Usuario;

import org.hibernate.Session;  
import org.hibernate.SessionFactory;  
import org.hibernate.cfg.Configuration;  
import org.hibernate.service.ServiceRegistry;  
import org.hibernate.service.ServiceRegistryBuilder;  

  
  
public class HibernateUtil {  
  
    private static SessionFactory factory;  
  
    static {  
        Configuration cfg = new Configuration();
        cfg.configure();// Nao preciso chamar .configure(), porque nao uso hibernate.cfg.xml, uso hibernate.properties  
        cfg.addAnnotatedClass(Edital.class);
        cfg.addAnnotatedClass(Lance.class);
        cfg.addAnnotatedClass(Perfil.class);
        cfg.addAnnotatedClass(Produto.class);
        cfg.addAnnotatedClass(Usuario.class);// Aqui coloco as classes que tem as anotacoes  
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();  
        factory = cfg.buildSessionFactory(serviceRegistry);  
  
    }  
      
    public static Session getSession() {  
        return factory.openSession();  
    }  
      
} 